<template>
  <el-card
    class="construction-container"
    v-loading="loading"
    :element-loading-text="loadinText"
  >
    <el-tabs type="card" @tab-click="changeTab" v-model="activeName">
      <el-tab-pane label="一级资质" name="first" class="firstConstruction">
        <el-table
          height="650"
          :data="firstConstructionList"
          type="border-card"
          style="width: 100%"
        >
          <el-table-column prop="cname" label="公司名称"> </el-table-column>
          <el-table-column fixed="right" label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                @click="$router.push(`/enterprise/detail/${scope.row.cname}`)"
                type="text"
                size="small"
                >查看详情</el-button
              >
            </template>
          </el-table-column>
          <template slot="empty">
            <el-empty description="暂无一级资质"></el-empty>
          </template>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="二级资质" name="second" class="secondConstruction">
        <el-table
          height="650"
          :data="secondConstructionList"
          type="border-card"
          style="width: 100%"
        >
          <el-table-column prop="cname" label="公司名称"> </el-table-column>
          <el-table-column fixed="right" label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                @click="$router.push(`/enterprise/detail/${scope.row.cname}`)"
                type="text"
                size="small"
                >查看详情</el-button
              >
            </template>
          </el-table-column>
          <template slot="empty">
            <el-empty description="暂无二级资质"></el-empty>
          </template>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="三级资质" name="third" class="thirdConstruction">
        <el-table
          height="650"
          :data="thirdConstructionList"
          type="border-card"
          style="width: 100%"
        >
          <el-table-column prop="cname" label="公司名称"> </el-table-column>
          <el-table-column fixed="right" label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                @click="$router.push(`/enterprise/detail/${scope.row.cname}`)"
                type="text"
                size="small"
                >查看详情</el-button
              >
            </template>
          </el-table-column>
          <template slot="empty">
            <el-empty description="暂无三级资质"></el-empty>
          </template>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <!-- 分页组件 -->
    <div style="height: 60px; margin-top: 19px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[15, 30, 40]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import {
  getFirstConstructionListApi,
  getSecondConstructionListApi,
  getThirdConstructionListApi
} from '@/api/qualifications'
export default {
  name: 'construction-page',
  created () {
    this.roleid = localStorage.getItem('crm-roleid')
    this.getFirstConstructionList()
  },
  data () {
    return {
      roleid: 0,
      loading: false,
      loadinText: '',
      page: 1,
      page_size: 15,
      total: 0,
      activeName: 'first',
      // 一级施工资质 列表
      firstConstructionList: [],
      // 二级施工资质 列表
      secondConstructionList: [],
      // 三级施工资质 列表
      thirdConstructionList: []
    }
  },
  methods: {
    // 获取 一级施工资质
    async getFirstConstructionList () {
      this.loading = true
      this.loadinText = '数据正在加载中!'
      const { data: res } = await getFirstConstructionListApi(
        this.page,
        this.page_size
      )
      // console.log('获取 一级施工资质', res)
      this.firstConstructionList = [...res.data.lists]
      this.total = res.data.num
      this.loading = false
      this.loadinText = ''
    },
    // 获取 二级施工资质
    async getSecondConstructionList () {
      this.loading = true
      this.loadinText = '数据正在加载中!'
      const { data: res } = await getSecondConstructionListApi(
        this.page,
        this.page_size
      )
      // console.log('获取 二级施工资质', res)
      this.secondConstructionList = [...res.data.lists]
      this.total = res.data.num
      this.loading = false
      this.loadinText = ''
    },
    // 获取 三级施工资质
    async getThirdConstructionList () {
      this.loading = true
      this.loadinText = '数据正在加载中!'
      const { data: res } = await getThirdConstructionListApi(
        this.page,
        this.page_size
      )
      // console.log('获取 三级施工资质', res)
      this.thirdConstructionList = [...res.data.lists]
      this.total = res.data.num
      this.loading = false
      this.loadinText = ''
    },
    // 切换tab栏 重置页码  判断选择的是哪个tab栏
    changeTab () {
      this.page = 1
      this.page_size = 15
      this.total = 0
      this.activeNameChange()
    },
    // 切换第几页
    handleCurrentChange (val) {
      this.page = val
      this.activeNameChange()
    },
    // 手动更改页码
    handleSizeChange (val) {
      this.page_size = val
      this.activeNameChange()
    },
    // 判断哪个tab栏被选中
    activeNameChange () {
      if (this.activeName === 'first') {
        // console.log('获取 一级施工资质')
        this.getFirstConstructionList()
      } else if (this.activeName === 'second') {
        // console.log('获取 二级施工资质')
        this.getSecondConstructionList()
      } else if (this.activeName === 'third') {
        // console.log('获取 三级施工资质')
        this.getThirdConstructionList()
      }
    }
  },
  watch: {}
}
</script>

<style lang="scss" scoped>
.construction-container {
  box-sizing: border-box;
  height: 837px;
  padding: 25px 40px 0px;
  // background-color: pink;
  .el-tabs {
    .el-tabs__item.is-active {
      background-color: #f5f7fa;
    }
  }
}
</style>
